CC=g++
CFLAGS=-std=c++11 -Wall -I.
LIBS=-lrealsense2 -lpng -lz -ljson-c -lserial

# The main target
all: rsdc

# Object files
OBJS = SerialControl.o SerialControl_c.o capture_controller.o rs-depth.o

# Main program
rsdc: $(OBJS)
	$(CC) $(CFLAGS) -o rsdc $(OBJS) $(LIBS)

# C++ source files
SerialControl.o: SerialControl.cpp SerialControl.h
	$(CC) $(CFLAGS) -c SerialControl.cpp

SerialControl_c.o: SerialControl_c.cpp SerialControl_c.h SerialControl.h
	$(CC) $(CFLAGS) -c SerialControl_c.cpp

# C source files with C++ linkage
capture_controller.o: capture_controller.c capture_controller.h SerialControl_c.h
	$(CC) $(CFLAGS) -c capture_controller.c

rs-depth.o: ../librealsense/examples/C/depth/rs-depth.c ../librealsense/examples/C/depth/example.h capture_controller.h SerialControl_c.h
	$(CC) $(CFLAGS) -c ../librealsense/examples/C/depth/rs-depth.c -I../librealsense/examples/C/depth

# Clean target
clean:
	rm -f rsdc $(OBJS)

# Install target
install: rsdc
	cp rsdc /usr/local/bin/

# Run target
run: rsdc
	./rsdc 